/*
 * @Author: Ryan Huang
 * @Date: 2019-04-02 20:38:14
 * @Description:
	写一个ATM函数，返回存款、取款两个内层函数
	存款、区块两个函数，都以一个金额为参数，返回存取之后的余额
	将各自的余额存在函数闭包中
	比尔、马云、你各自胡乱存取一通，输出各自余额
*/
package main

import "fmt"

type Balance struct {
	Name   string
	Amount float32
}

func main() {
<<<<<<< HEAD
	Bill := Balance{"Bill", 87634.00}
	Mayun := Balance{"Ma", 23413.00}
	Me := Balance{"Ryan", 312.00}
	save := atm(true)
	save(&Bill, 1.99)
	save(&Mayun, 2.99)
	save(&Me, 3)
	withdraw := atm(false)
	withdraw(&Bill, 9.45)
	withdraw(&Mayun, 12.56)
	withdraw(&Me, 13.1)
=======
	Bill := Balance{"Bill", 888888.00}
	Mayun := Balance{"Ma", 222222.00}
	Me := Balance{"Ryan", 12.00}
	save := atm(true)
	save(&Bill, 10.99)
	save(&Mayun, 20.99)
	save(&Me, 3)
	withdraw := atm(false)
	withdraw(&Bill, 90.45)
	withdraw(&Mayun, 10.56)
	withdraw(&Me, 1.1)
>>>>>>> 5ff4299df15cebcc96b503c1bef32f6520030e85
	fmt.Println(Bill, Mayun, Me)
}

func atm(inOrOut bool) func(*Balance, float32) { // true 表示存钱 in， false表示取钱 out
	if inOrOut {
		return func(balance *Balance, Amount float32) {
			balance.Amount += Amount
		}
	} else {
		return func(balance *Balance, Amount float32) {
			balance.Amount -= Amount
		}
	}
}
